put quote & replacestring & quote into replaceWithWhole
put "put " & replaceWithWhole & " into " & markedText into replaceAction
send replaceAction
end if
end replace
-- part contents for background part 1
----- text -----
where ReplaceWithString is the string to replace the Find What String. As with the first handler, you need double neutral quotation marks (") around the argument if it is more than one word. This handler uses the information in the global variable declared by the first handler to find the character positions for placing the new string. It then does the replacement. The reason there are two handlers is that this way it is possible to search for a particular string and check it (your own script could check the foundLine, for example). If it checks out to be the one that should be replaced, the replace handler can be then called to do the replacement.
To copy the scripts to your stack, click the button below, and its scripting dialog will appear containing the the two aforementioned scripts (below its own mouseUp handler).